package com.meila.cms.services.impl;

import java.util.Date;
import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.meila.cms.dao.PartsMapper;
import com.meila.cms.entity.AjaxObj;
import com.meila.cms.model.PartsModel;
import com.meila.cms.services.IDrawingService;
import com.meila.cms.util.page.PageBoundsUtil;
import com.meila.cms.util.page.Pager;

@Service
public class DrawingService implements IDrawingService {

	private PartsMapper partsMapper;
 
	
	public PartsMapper getPartsMapper() {
		return partsMapper;
	}

	@Inject
	public void setPartsMapper(PartsMapper partsMapper) {
		this.partsMapper = partsMapper;
	}



	@Override
	public Pager<PartsModel> findParts(PartsModel partsModel) {
		// TODO Auto-generated method stub
		
		//封装PageBounds对象
		PageBounds pageBounds = PageBoundsUtil.PageBoundsOrderExtend("partsNo.desc");
		
		//获取用户总数
		int count =	partsMapper.findPartsCount(partsModel,pageBounds);
		
		//获取用户分页列表集合信息
		List<PartsModel> list = partsMapper.findParts(partsModel,pageBounds);
		//封装用户分页的Pager对象
		Pager<PartsModel> pages = new Pager<PartsModel>(count,list);
		return pages;
	}

	@Override
	public AjaxObj update(PartsModel partsModel) {
		// TODO Auto-generated method stub
		AjaxObj  ajaxObj=new AjaxObj();
		try {
			partsModel.setUpdateTime(new Date());
			partsMapper.updateByPrimaryKeySelective(partsModel);
			ajaxObj.setMsg("操作成功");
		} catch (Exception e) {
			// TODO: handle exception
			ajaxObj.setResult(false);
			ajaxObj.setMsg("操作失败");
			e.printStackTrace();
		}
		
		
		return ajaxObj;
	}

}
